/**
 *	@author Juntalis
 */

/**
 * Converts all urls in plaintext to full-fledged HTML links.
 * @param {String} text The text you want to search for urls.
 * @return {String} The text, with html links in place.
 */
/*
String.prototype.ToLinks = function()
{
	text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
		function(url) {
			nice = url;
			if( url.match('^https?:\/\/') )
				nice = nice.replace(/^https?:\/\//i,'');
			else
				url = 'http://'+url;
			return '<a target="_blank" rel="nofollow" href="'+ url +'">'+ nice.replace(/^www./i,'') +'</a>';
		}
	);
	
	return text;
}
*/

/**
 * Escapes all html elements in a string with the proper HTML ASCII escape codes.
 * @return {String}	Escaped html.
 */
String.prototype.EscapeHtml = function () {
	return (this
		.replace(/&/g, '&amp;')
		.replace(/>/g, '&gt;')
		.replace(/</g, '&lt;')
		.replace(/\^(?:\d{1,2})/g, "")
		.replace(/"/g, '&quot;'));
}

/**
 * Converts things like line breaks and tabs to their html counterparts.
 * @return {String} The new text.
 */
String.prototype.TextToHtml = function () {
	return (str.replace(/\n/g, '<br />').replace(/\t/g, '&nbsp;&nbsp;'));
}

/**
 * This should be used before EscapeHtml and before you start putting in your own BBCode. That way, no one else can do it.
 */
String.prototype.PreBBCode = function() {
	return this.replace(/\[/g, '&#91;').replace(/\]/g, '&#93;');
}	
